package com.me.bbs.common;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author Liming Wang
 * @Description
 * @Create 2023/1/9 18:08
 */
@AllArgsConstructor
@Data
public class Resp<T> {
    private T data;
    private int code;
    private String msg;

    public static <T> Resp<T> success(T data, String msg) {
        return new Resp<>(data, CommonConst.SUCCESS_CODE, msg);
    }

//    public static <T> Resp<T> success(String msg) {
//        return new Resp<>(null, CommonConst.SUCCESS_CODE, msg);
//    }
    public static <T> Resp<T> success(T data) {
        return new Resp<>(data, CommonConst.SUCCESS_CODE, "成功");
    }
    public static <T> Resp<T> success() {
        return new Resp<>(null, CommonConst.SUCCESS_CODE, "成功");
    }

    public static <T> Resp<T> error(T data, String msg) {
        return new Resp<>(data, CommonConst.ERROR_CODE, msg);
    }

    public static <T> Resp<T> error(String msg) {
        return new Resp<>(null, CommonConst.ERROR_CODE, msg);
    }
    public static <T> Resp<T> error() {
        return new Resp<>(null, CommonConst.ERROR_CODE, "服务器出错");

    }
    public static <T> Resp<T> error(int code, String msg) {
        return new Resp<>(null, code, msg);

    }
}
